<template>
  <FlowUserTaskNodeHistory :request="request" :dataSource="dataSource"/>
</template>
<script>
import {createProps, isEmpty} from '@/utils';
import {createService} from '@/request/service';
import FlowUserTaskNodeHistory from '@/components/flow/nodeHistoryDetail/components/FlowUserTaskNodeHistory.vue';
import Section from '@/components/Section/Section.vue';

export default {
  name: 'FormFlowHistory',
  components: {Section, FlowUserTaskNodeHistory},
  props: {
    formId: createProps(String),
    request: createProps(Object, () => ({
      baseURL: '/h-flow',
      headers: {
        flow: 'h-flow'
      },
    })),
  },
  data() {
    return {
      dataSource: [],
      history: [],
      current: [],
    };
  },
  methods: {
    loadHistory() {
      if (isEmpty(this.formId)) {
        this.dataSource = [];
        return;
      }
      createService(this.request).get('/flow/getUserTaskHistoryByFormId', {params: {formId: this.formId}}).then(data => {
        this.history = data.history || [];
        this.current = data.current || [];
        this.dataSource = [...this.history];
      });
    },
  },
  watch: {
    dataSource() {
      this.$emit('loaded', this.history);
    },
    formId: {
      handler() {
        this.loadHistory();
      },
      immediate: true
    }
  }
};
</script>
<style>
.h-form-flow-history {

}
</style>